package com.xm.controller;

import com.xm.common.pojo.JsonResult;
import com.xm.service.ItemCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@CrossOrigin
@RequestMapping(value = "/itemCar/")
@RestController()
public class ItemCarController {
    @Autowired
    ItemCarService itemCarService;

    @PostMapping("{userName}/{itemId}")
    JsonResult saveItemCar(@PathVariable String userName,@PathVariable Integer itemId){
        itemCarService.saveItemCar(userName, itemId);
        return new JsonResult("添加购物车成功");
    }

    @DeleteMapping("{userName}/{itemId}")
    JsonResult deleteItemCar(@PathVariable String userName,
                             @PathVariable Integer itemId){
        itemCarService.deleteItemCar(userName,itemId);
        return new JsonResult("删除购物车成功");
    }

    @GetMapping("{username}")
    JsonResult findItemByUserName(@PathVariable String username){

        return new JsonResult(itemCarService.findItemByUserName(username));
    }
}
